<meta title="BundleJs更新包管理">
<div class="p">
    <div class="panel panel-success">
        <div class="panel-heading">
            <h4>BundleJs包发布管理</h4>
        </div>
        <div class="panel-body">
            <div class="p-b">
                <form class="form-inline m-b-wrapper-xs pull-left" id="form" s="form"
                      s-form="{action:function(){$page.node.val(1); $bundleJsPackagesGrid.refresh()}}"
                >
                    <select class="form-control input-sm" s="select"
                            s-build="S.get('/api/enum/valuesMap/core.enums.AppPlatform')"
                            name="platform">
                        <option value="">选择平台</option>
                    </select>
                    <input autocomplete="off" type="hidden" name="page" id="page" value="1"/>
                    <input autocomplete="off" type="submit" class="btn btn-default btn-sm" value="查找"/>
                </form>
                <div class="pull-right">
                    <input autocomplete="off" type="button" s-click="add()" class="btn btn-primary btn-sm" value="新增"/>
                </div>
            </div>
            <table
                    id="bundleJsPackagesGrid"
                    s='datac,nda'
                    s-data="Smart.cleanJsonRef(S.get('/api/bundleJsPackage/search', $form.node.serialize()))"
                    class="table table-stripped table-bordered">
                <tr>
                    <th>版本号</th>
                    <th>平台</th>
                    <th>平台版本号</th>
                    <th>使用缓存</th>
                    <th>显示IOS隐藏内容</th>
                    <th>升级</th>
                    <th>创建时间</th>
                    <th class="text-center">状态</th>
                    <th class="text-right">操作</th>
                </tr>
                <tbody s="loop" s-data-filter="'results'">
                <tr s-loop-role="empty">
                    <td colspan="9" class="alert alert-warning">
                        暂无宝贝，请先进行添加
                    </td>
                </tr>
                <tr s-loop-role="row" s="row,datac">
                    <td name="version"></td>
                    <td class="text-center" name="platform"></td>
                    <td class="text-center" name="platformVersion"></td>
                    <td>
                        <label class="s-checkbox-switch">
                            <input autocomplete="off" type="checkbox" s-change="useCache(this)" name="useCache" value="true" />
                            <span class="s-checkbox-indicator"></span>
                        </label>
                    </td>
                    <td>
                        <label class="s-checkbox-switch">
                            <input autocomplete="off" type="checkbox" s-change="iosShow(this)" name="iosShow" value="true" />
                            <span class="s-checkbox-indicator"></span>
                        </label>
                    </td>
                    <td>
                        <label class="s-checkbox-switch">
                            <input autocomplete="off" type="checkbox" s-change="showUpdate(this)" name="showUpdate" value="true" />
                            <span class="s-checkbox-indicator"></span>
                        </label>
                    </td>
                    <td name="createTime"></td>
                    <td class="text-center" s="tpl">
                        <label class="label
                            {%
                                switch(this.status) {
                                    case 'WAIT_PUBLISH': out.print('label-warning'); break;
                                    case 'PUBLISHED': out.print('label-success'); break;
                                    default: out.print('label-default');break;
                                }
                            %}
                        ">{%=this.status%}</label>
                    </td>
                    <td s="tpl" class="text-right">
                        {%if(this.status == 'WAIT_PUBLISH') {%}
                        <input autocomplete="off" type="button" s-click="publish(this)" class="btn btn-xs btn-link" value="发布"/>
                        {%} else {%}
                        {%}%}
                        <input autocomplete="off" type="button" s-click="del(this)" class="btn btn-xs btn-link" value="删除"/>
                    </td>
                </tr>
                </tbody>
                <tfoot>
                <tr>
                    <td colspan="8" class="text-right">
                        <ul s="pagination" id="sellerPagination"
                            s-pagination="{action:function(){$page.node.val(this); $bundleJsPackagesGrid.refresh()}}"
                            class="pagination pagination-sm">
                        </ul>
                        共有<span name="total"></span>个数据
                    </td>
                </tr>
                </tfoot>
            </table>
        </div>
    </div>
</div>
<script type="text/javascript">
    function publish($s) {
        var data = $s.parent().data();
        S.confirm("确认发布吗?").done(function() {
            S.put("/api/bundleJsPackage/" + data.id).done(function() {
                $bundleJsPackagesGrid.refresh()
            })
        })
    }
    function del($s) {
        var data = $s.parent().data();
        S.confirm("确认删除吗?").done(function() {
            S.remove("/api/bundleJsPackage/" + data.id).done(function() {
                $bundleJsPackagesGrid.refresh()
            })
        })
    }
    function add() {
        S.popupOpen("/bundlejs/bundleJsPackage-add.html").done(function(rs) {
            rs && $bundleJsPackagesGrid.refresh()
        })
    }

    function useCache($this) {
        var data = $this.data();
        S.put("/api/bundleJsPackage/use-cache/" + data.id + "-" + $this.node.prop('checked')).done(function() {

        })
    }

    function iosShow($this) {
        var data = $this.data();
        S.put("/api/bundleJsPackage/ios-show/" + data.id + "-" + $this.node.prop('checked')).done(function() {

        })
    }

    function showUpdate($this) {
        var data = $this.data();
        S.put("/api/bundleJsPackage/show-update/" + data.id + "-" + $this.node.prop('checked')).done(function() {

        })
    }

</script>